#include <iostream>
#include <cstdlib>
using namespace std;

enum GameStatus
{
    WIN,
    LOSE,
    PLAYING
}; //枚举类型，默认值顺次为0,1,2，大括号

int main()
{
    int sum,myPoint;                //定义和数，我的点数
    GameStatus status;              //游戏状态
    unsigned seed;                  //定义随机数种子
    int rollDice();                 //调用函数前先声明投骰子函数

    cout << "Please input an unsigned integer : ";
    cin >> seed;                    //输入随机数种子
    srand(seed);                    //将种子传递给rand
    sum = rollDice();               //掷骰子、计算和

    switch(sum)
    {
    case 7:                         //和数为7获胜
    case 11:                        //两个标号共用一组语句，两者为或关系
        status = WIN;
        break;

    case 2:                         //和为2,3或12为输
    case 3:
    case 12:
        status = LOSE;
        break;

    default:                        //和为其他情况时，记下点数
        status = PLAYING;
        myPoint = sum;
        cout << "myPoint is " << myPoint << endl;
        break;
    }

    while(status == PLAYING)        //游戏状态为PKAYING，游戏继续
    {
        sum = rollDice();
        if(sum == myPoint)          //某轮的和数等于点数则取胜
          status = WIN;
        else if (sum == 7)          //和数为7则输
            status = LOSE;
    }

    //状态不为PLAYING时，结束循环，输出结果
    if(status == WIN)
        cout << "player wins" << endl;
    else
        cout << "player loses" << endl;
    return 0;
}

//投骰子过程、计算、输出和
int rollDice()
{
    int die1 = 1 + rand() % 6;
    int die2 = 1 + rand() % 6;
    int sum = die1 + die2;
    cout << "player rolled : " << die1 <<
    "+" << die2 << "=" << sum <<endl;
    return sum;
}

